<template>
  <div class="notice">
    <van-nav-bar title="公告列表" left-arrow @click-left="onClickLeft" />
    <div class="notice-list">
      <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
        <van-list
          v-model="loading"
          :finished="finished"
          finished-text="没有更多了"
          @load="getNoticeList"
        >
          <div
            class="notice-list-item"
            v-for="item in noticeList"
            :key="item.id"
            @click="toDetail(item.id)"
          >
            <van-card
              :desc="item.detail"
              :title="item.title"
              centered
              :thumb="item.urlList && item.urlList.length > 0 ? item.urlList[0] : defaultPic"
              style="margin-bottom: 15px;"
            >
              <template #tags>
                <span class="van-diy-tags">{{ item.updateTimeStr }}</span>
              </template>
            </van-card>
          </div>
        </van-list>
      </van-pull-refresh>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      defaultPic: require('../assets/images/diy-ban.jpg'),
      loading: false,
      finished: false,
      refreshing: false,
      noticeList: [],
      paginationParams: {
        isPublish: 1,
        pageNo: 1,
        pageSize: 10
      }
    }
  },
  created() {
    // this.getNoticeList()
  },
  methods: {
    toDetail(id) {
      this.$router.push({
        path: '/noticeInfo?id=' + id
      })
    },
    onClickLeft() {
      history.back()
    },
    getNoticeList() {
      this.$http.getNoticeList(this.paginationParams).then((res) => {
        console.log(res)
        if (res.success) {
          if (this.refreshing) {
            this.noticeList = []
            this.refreshing = false
          }
          if (res.model.data.length > 0) {
            let result = res.model.data
            this.paginationParams.pageNo++
            this.loading = false
            this.noticeList = this.noticeList.concat(result)
          }
          if (this.noticeList.length >= res.model.totalCount) {
            this.finished = true
          }
        }
      })
    },
    onRefresh() {
      this.paginationParams.pageNo = 1
      this.finished = false
      this.loading = true
      this.getNoticeList()
    }
  }
}
</script>

<style lang="less" scoped>
.notice-list {
  padding: 15px 0;
  .van-pull-refresh {
    height: calc(100vh - 130px);
  }
  .van-card__thumb {
    margin-right: 0.2rem;
  }
  .van-card__title {
    display: block;
    font-size: 0.32rem;
    height: 0.6rem;
    line-height: 0.6rem;
    overflow: hidden;
    white-space: nowrap;
    text-overflow: ellipsis;
    color: #333;
    text-align: left;
  }
  .van-card__desc {
    display: block;
    font-size: 0.28rem;
    max-height: 0.6rem;
    height: 0.6rem;
    line-height: 0.6rem;
    overflow: hidden;
    text-align: justify;
    color: #666;
    margin: 0.1rem 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .van-diy-tags {
    float: right;
  }
}
</style>
